# 导入心电信号处理函数库
from cProfile import label
import numpy as np
import wfdb
# 导入python的类matlab绘图函数库
import matplotlib.pyplot as plt
from scipy import signal
from myutils.NcUtils import fliter, DWT, low_pass, median_filter

# 读取本地的100号记录，从0到25000，读取模拟信号,通道0
# record = wfdb.rdrecord('../data/mit-bih-arrhythmia-database-1.0.0/100', sampfrom=0, sampto=25000, physical=True,
#                        channels=[0, ])
#
# ventricular_signal = record.p_signal.T[0][0:640]
# ventricular_signal1 = fliter(record.p_signal.T[0])[0:640]
# ventricular_signal6 = fliter1(record.p_signal.T[0])[0:640]
# ventricular_signal2 = DWT(record.p_signal.T[0])[0:640]
# ventricular_signal3 = low_pass(record.p_signal.T[0])[0:640]
# ventricular_signal4 = median_filter(record.p_signal.T[0])[0:640]
#
# # 设置中文字体（例如黑体 SimHei）
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 或者 ['Microsoft YaHei']
# # 解决保存图像时负号'-'显示为方块的问题
plt.rcParams['axes.unicode_minus'] = False
#
# # 打印标题
# plt.title("ECG信号")
# # 打印信号
# plt.plot(ventricular_signal, label='原始信号')
# plt.plot(ventricular_signal1, label='fliter', color='red')
# plt.plot(ventricular_signal6, label='1', color='black')
# # plt.plot(ventricular_signal2,label='DWT', color='black')
# # plt.plot(ventricular_signal3,label='low_pass', color='yellow')
# # plt.plot(ventricular_signal4,label='median_filter', color='brown')
# # 显示图像
# plt.legend()g
# plt.show()

record = wfdb.rdrecord('../data/mit-bih-arrhythmia-database-1.0.0/100', sampfrom=0, sampto=64000, physical=True,
                       channels=[0, ])
signal_annotation = wfdb.rdann('../data/mit-bih-arrhythmia-database-1.0.0/100', "atr", sampfrom=0, sampto=1000)
# 打印标注信息
ECG= record.p_signal.T[0][1300:3400]
# ECG = fliter(record.p_signal.T[0])[1300:3400]
plt.figure(figsize=(10, 5))
plt.plot(ECG)
# 按坐标在散点图上绘点
# for index in signal_annotation.sample:
#     plt.scatter(index, ECG[index], marker='*', s=200)
plt.title("心电信号序列图")
plt.xlabel('采样点')
plt.ylabel('振幅')
plt.legend()
# plt.show()
plt.savefig('1.jpg', dpi=600, bbox_inches='tight')
